#include <cppunit/config/SourcePrefix.h>
#include "TestParent.h"
#include <string>

void TestParent::setUp() {
	parent = Parent();
	parent.addParent(1,2);
	parent.addParent(1,3);
	parent.addParent(3,4);
	parent.addParent(3,5);
	parent.addParent(3,6);
	parent.addParent(1,7);
	parent.addParent(1,8);
	parent.addParent(8,9);
	parent.addParent(8,10);
	parent.addParent(11,12);
}

void TestParent::tearDown() {
}

CPPUNIT_TEST_SUITE_REGISTRATION( TestParent );

void TestParent::testAddParent(){
	int index1 = parent.addParent(11,13);
	int index2 = parent.addParent(11,14);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("11th item added; index 10", 10, index1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("12th item added; index 11", 11, index2);
}

void TestParent::testGetParent(){
	vector<pair<int,int>> anyany = parent.getParent(ANYVALUE, ANYVALUE);
	int size = anyany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("All results return", 10, size);

	vector<pair<int,int>> anynum = parent.getParent(ANYVALUE, 3);
	size = anynum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Only (allowed) 1 parent to be found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("One result (1,3)", 1, anynum.at(0).first);

	vector<pair<int,int>> numany = parent.getParent(1, ANYVALUE);
	size = numany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("4 results found", 4, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (1,2)", 2, numany.at(0).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (1,3)", 3, numany.at(1).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("third result (1,7)", 7, numany.at(2).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("fourth result (1,8)", 8, numany.at(3).second);

	vector<pair<int,int>> numnum = parent.getParent(1, 2);
	size = numnum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("1 result found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (1,2)", 1, numnum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (1,2)", 2, numnum.at(0).second);

	vector<pair<int,int>> none = parent.getParent(3, 3);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("no result found", 0, size);
}

void TestParent::testGetParentStar(){
	vector<pair<int,int>> anyanyStar = parent.getParentStar(ANYVALUE, ANYVALUE);
	int size = anyanyStar.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("15 (10+5) results return, i.e. + (1,4), (1,5), (1,6), (1,9), (1,10)", 15, size);

	vector<pair<int,int>> anynumStar = parent.getParentStar(ANYVALUE, 6);
	size = anynumStar.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("2 results found, i.e. (1,6), (3,6)", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (1,6)", 1, anynumStar.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (3,6)", 3, anynumStar.at(1).first);

	vector<pair<int,int>> numanyStar = parent.getParentStar(1, ANYVALUE);
	size = numanyStar.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("9 (4+5) results return, i.e. + (1,4), (1,5), (1,6), (1,9), (1,10)", 9, size);

	vector<pair<int,int>> numnumStar = parent.getParentStar(1, 10);
	size = numnumStar.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("One result found only", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (1,10)", 1, numnumStar.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (1,10)", 10, numnumStar.at(0).second);

	vector<pair<int,int>> none = parent.getParentStar(10, 1);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No result found", 0, size);

	none = parent.getParentStar(15, ANYVALUE);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No result found", 0, size);

	none = parent.getParentStar(ANYVALUE, 15);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No result found", 0, size);
}